import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:palyer/app/core/constans/storage.dart';
import 'package:palyer/app/core/http/http.dart';
import 'package:palyer/app/core/utils/storage_util.dart';
import 'package:palyer/app/core/utils/user_manager.dart';

import 'package:palyer/app/core/values/dimens.dart';

/// 全局静态数据
class Global {
  /// 是否第一次打开
  static bool isFirstOpen = false;

  /// 是否 release
  static bool get isRelease => const bool.fromEnvironment('dart.vm.product');

  /// app 相关信息
  static PackageInfo packageInfo = PackageInfo(
    appName: 'Unknown',
    packageName: 'Unknown',
    version: 'Unknown',
    buildNumber: 'Unknown',
    buildSignature: 'Unknown',
  );

  initToast() {
    //EasyLoading 是一个全局单例, 所以你可以在任意一个地方自定义它的样式:
    EasyLoading.instance
      ..displayDuration = const Duration(milliseconds: 2000)
      ..indicatorType = EasyLoadingIndicatorType.fadingCircle
      ..loadingStyle = EasyLoadingStyle.custom
      ..toastPosition = EasyLoadingToastPosition.bottom
      ..contentPadding = EdgeInsets.symmetric(horizontal: AppDimens.dp10, vertical: AppDimens.dp5)
      ..indicatorSize = 45.0
      ..radius = 10.0
      ..progressColor = Colors.black
      ..backgroundColor = const Color(0xff5F6368)
      ..indicatorColor = Colors.white
      ..textColor = Colors.white
      ..maskColor = Colors.black.withOpacity(0.5)
      ..userInteractions = false // 当loading展示的时候，是否允许用户操作.
      ..dismissOnTap = false; // 点击背景是否关闭.
  }

  /// init
  static Future init() async {
    // 运行初始
    WidgetsFlutterBinding.ensureInitialized();

    PackageInfo.fromPlatform().then((value) => packageInfo = value);

    // DeviceUtil.init();

    await StorageUtil.init();
    // await AppLocaleUtil.init();
    UserManager.init();
    // HttpProxyUtil.init();
    HttpUtil();
    // 读取设备第一次打开
    isFirstOpen = StorageUtil.getBool(StorageConstants.firstOpen) ?? true;
    StorageUtil.setBool(StorageConstants.firstOpen, false);

    // android 状态栏为透明的沉浸
    if (GetPlatform.isAndroid) {
      const systemUiOverlayStyle =
          SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}
